package fair.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

import java.util.Date;

/**
 * @author fair_wu
 * @version v1.0
 * @package fair.utils
 * @date 2021-01-28 下午 14:02
 */
public class MailUtils{
    public void sendMsg() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml",
                "applicationContext-email.xml");
        MailSender ms = (MailSender) ac.getBean("mailSender");

        SimpleMailMessage smm = new SimpleMailMessage();
        // 发送
        smm.setFrom("11--@qq.com");//此处省略邮箱
        // 接收
        smm.setTo("18----@163.com");
        // 主题
        smm.setSubject("库存预警" + System.currentTimeMillis());
        // 内容
        smm.setText("库存预警");
        //
        smm.setSentDate(new Date());
        ms.send(smm);
        System.out.println("end");
    }

    public static void main(String[] args) {
        MailUtils emailUtil = new MailUtils();
        emailUtil.sendMsg();
    }
}
